/*********************************
File name:  ebmanualworker1-10.do
DATE:		3/2024
PURPOSE:    This do file creates the EB part of Figures 2 and 3 
            (Fig2: Manual workers support for SD (RR) and 
			 the composition of SD (RR) over time; Fig3: 
			 manual workers support for other party families)
            It is organized in the following way:
			1. Creates occupational categorization by sector (drwing on ESS ISCO clasification)
			2. Creates EB part of Fig. 2a (Rate of support for SDPs)
			3. Creates EB part of Fig. 2b (Rate of support for FRPs)
			4. Creates EB part of Fig. 2c (Composition of SDPsR)
			5. Creates EB part of Fig. 2d (Composition of the FRPs)
			6. Creates EB part of Conservative rate of suuport
			7. Creates EB part of CD rate of support
			8. Creates EB part of RL rate of support
			9. Creates EB part of LIB rate of support
			10.Creates EB part of GRN rate of support
INPUT: 		eb_modified1-10.dta 
LOG FILE:   ebmanualworker1-10.log
AUTHOR:     Orit Kedar, Lotem Halevy, Odelia Oshri
*********************************/
use "C:\Users\User\Downloads/eb_modified1-10.dta", clear
capture log using "ebmanualworker1-10.log", replace
cd "C:\Users\User\Desktop\Figures"

set scheme s2mono
gen year_2dig = string(mod(year,100), "%02.0f")  
gen cntryear=cntry+year_2dig
ta cntryear
egen countcntryear=group(cntryear)
ta countcntryear /*339 cntryears observations, reported in the paper*/

/* Part 1: Create occupational categorization */

/* The Eurobarometer does not have the same coding of occupations as the ESS. In order to attach ESS categorization of occupations (sectors) to Eurobarometer data, we cross-
reference the verbal description of occupations in the Eurobarometer with the verbal
description in the ESS and get the category number from the ESS (the first digit of the
categorization there).The ESS variable is constructed based on ISCO classifications.  
These sectors appear in Table 1.
.*/

tab occup, miss

gen sector=.
replace sector=6  if occup==110 /*farmer/fisherman*/
replace sector=6  if occup==111 /*farmer*/
replace sector=6  if occup==112 /*fisherman*/
replace sector=2  if occup==120 /*self-employeed professional*/
replace sector=1  if occup==130 /*owner of a shop, craftsman, business prop.*/
replace sector=1  if occup==131 /*owner of a shop, business prop. Self-employed*/
replace sector=1  if occup==132 /*owner of a shop, business prop. partner/self em.*/
replace sector=2  if occup==210 /*emmployed professional*/
replace sector=1  if occup==220 /*executive, top managment*/
replace sector=3  if occup==230 /*middle managment*/
replace sector=4  if occup==310 /*employed, working at desk*/
replace sector=4  if occup==311 /*white collar, office worker*/
replace sector=4  if occup==312 /*other office employee*/
replace sector=5  if occup==320 /*non-office employee, non- manual in service*/
replace sector=5  if occup==321 /*employeed, not at desk but travelling*/
replace sector=5  if occup==322 /*employed pos.service*/
replace sector=8  if occup==410 /*manual worker*/
replace sector=7  if occup==411 /*skilled manual worker*/
replace sector=3  if occup==412 /*supervisor*/
replace sector=8  if occup==413 /*other unskilled manual worker*/
replace sector=10 if occup==510 /*housewife*/
replace sector=0  if occup==522 /*military worker*/
replace sector=11 if occup==540 /*unemployed*/


drop if occup==500 /*housemaker/student/military/retired; no way to distinguish*/
drop if occup==520 /*student/military; no way to distinguish*/
drop if occup==521 /*student*/
drop if occup==530 /*retired: no way to tell what prev occupation was, also irre.
	                 in our theory about the risk of job replacement, no job*/
drop if occup>997 /*Dont know/ Not Applicable*/ 


ta sector
/*% men and women working in manual sectors*/
gen manul_dum=.
replace manul_dum=1 if (sector==7 | sector==8|  sector==9)
replace manul_dum=0 if (sector<6& sector>0)

by gndr, sort: tab manul_dum /*37% of men and 25% of women are manual workers, this information is reported in the paper*/ 

/*% men and women working in communication sectors*/
gen com_dum=.
replace com_dum=1 if (sector==1 | sector==4|  sector==2)
replace com_dum=0 if (sector==3| sector==5 | sector==7 | sector==8 | sector==9 )
by gndr, sort: tab com_dum /*52% of women and 46% of men are communication workers*/

/* generate manual worker variable, sectors 7,8,9: 
 craft and related trades, plant and machine operators, elementary occupation*/
gen mnlwrk=.
replace mnlwrk=1 if (sector<=9 & sector>=7)
replace mnlwrk=0 if sector<6 /* old code included 6*/

/* Manual men and women workers */
gen mwm=1 if (mnlwrk==1 & gndr==1)
gen mwf=1 if (mnlwrk==1 & gndr==0)

/*Communication men and women workers*/
gen cwm=1 if (com_dum==1 & gndr==1)
gen cwf=1 if (com_dum==1 & gndr==0)

/* Part 2: EB part of Fig. 2a (Rate of support for the SD)*/

*Numerator: Number of manual workers M/F + general sample voting SD
gen mwmsd=1 if (mnlwrk==1 & gndr==1 & prtyfam_sd==1)
gen mwfsd=1 if (mnlwrk==1 & gndr==0 & prtyfam_sd==1)
by  year cntry, sort: egen nmwmsd=total(mwmsd)   if mwmsd==1
by  year cntry, sort: egen nmwfsd=total(mwfsd)   if mwfsd==1
by  year cntry, sort: egen nsdv=total(prtyfam_sd)  if prtyfam_sd==1

*Numerator: Number of communiction workers M/F + general sample voting SD
gen cwmsd=1 if (com_dum==1 & gndr==1 & prtyfam_sd==1)
gen cwfsd=1 if (com_dum==1 & gndr==0 & prtyfam_sd==1)
by  year cntry, sort: egen ncwmsd=total(cwmsd)   if cwmsd==1
by  year cntry, sort: egen ncwfsd=total(cwfsd)   if cwfsd==1

* Denominator: Number of manual workers M/F who voted and number of voters
gen mwmv=1 if (mnlwrk==1 & gndr==1)
by year cntry, sort: egen nmwmv=total(mwmv) if mwmv==1
gen mwfv=1 if (mnlwrk==1 & gndr==0)
by year cntry, sort: egen nmwfv=total(mwfv) if mwfv==1
gen vote=.
replace vote=1 if voteint>1
by year cntry, sort: egen nv=total(vote) 

* Denominator: Number of communication workers M/F who voted and number of voters
gen cwmv=1 if (com_dum==1 & gndr==1)
by year cntry, sort: egen ncwmv=total(cwmv) if cwmv==1
gen cwfv=1 if (com_dum==1 & gndr==0)
by year cntry, sort: egen ncwfv=total(cwfv) if cwfv==1

*Proportions
gen mwmsd_mwmv 	=nmwmsd/nmwmv
gen mwfsd_mwfv   =nmwfsd/nmwfv
gen sdv_v     =nsdv/nv

gen cwmsd_cwmv 	=ncwmsd/ncwmv
gen cwfsd_cwfv   =ncwfsd/ncwfv

* generate % male manual workers per country*/
by year cntry, sort: egen mwmsdcntry=max(mwmsd_mwmv)
egen cntryuniquemwm=tag(mwmsdcntry)
bys year cntry:egen cntryunique=sum(mwmsdcntry) if cntryuniquemwm==1
* generate % female manual workers per country*/
by year cntry, sort: egen mwfsdcntry=max(mwfsd_mwfv)
egen cntryuniquemwf=tag(mwfsdcntry)
bys year cntry:egen cntryunique1=sum(mwfsdcntry) if cntryuniquemwf==1
* generate % sd voters per country*/
by year cntry, sort: egen sdv=max(sdv_v)
egen cntryuniquesdv=tag(sdv)
bys year cntry:egen cntryunique2=sum(sdv) if cntryuniquesdv==1

* generate % male communication workers per country*/
by year cntry, sort: egen cwmsdcntry=max(cwmsd_cwmv)
egen cntryuniquecwm=tag(cwmsdcntry)
bys year cntry:egen cntryunique3=sum(cwmsdcntry) if cntryuniquecwm==1
* generate % female communication workers per country*/
by year cntry, sort: egen cwfsdcntry=max(cwfsd_cwfv)
egen cntryuniquecwf=tag(cwfsdcntry)
bys year cntry:egen cntryunique4=sum(cwfsdcntry) if cntryuniquecwf==1

/*APPENDIX: Figure D3: we generate figure EB 2a without Italy, as the main left wing party in Italy during the 70s and 80s is the PCI, a communist radical left party*/
twoway lpolyci cntryunique2 year if (cntryrr==1 & nt1!="IT"),  degree(3) lcolor(gs8) lwidth(thick) fcolor(gs10*.8) acolor(538rs9%50) alsty(nono) level(95)  ///
|| scatter sdv_v year if cntryrr==1 & nt1!="IT", jitter(3) msymbol(i) mlabel(nt1) mlabsize(small)  graphregion(color(white)) ///
                                         mlabcolor(gs8) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique1 year if cntryrr==1 & nt1!="IT", degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)  ///
|| scatter mwfsd_mwfv year if cntryrr==1 & nt1!="IT", jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(black) xtitle("") ///
|| lpolyci cntryunique year if cntryrr==1 & nt1!="IT",  degree(3) lcol(red) fcolor(red*.7) acolor(538rs9%50) alsty(nono) ///
level(95) lwidth(thick) lpattern(solid) legend(off) ///
|| scatter mwmsd_mwmv year if cntryrr==1 & nt1!="IT", ytitle("Support for SDPs") caption(Source: EB trendfile) jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(red) xtitle("") 
graph save "EB 2a", replace

*MAIN TEXT: Figure 2a: simplified version of the graph
twoway lpolyci cntryunique2 year if (cntryrr==1 & nt1!="IT"),  degree(3) lcolor(gs8) lwidth(thick) fcolor(gs10*.8) acolor(538rs9%50) alsty(nono) level(95) fxsize(100)  graphregion(color(white))   ||			lpolyci cntryunique1 year if cntryrr==1 & nt1!="IT", degree(3) lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) lpattern(solid) level(95) lwidth(thick) lpattern(solid)|| lpolyci cntryunique year if cntryrr==1 & nt1!="IT",  degree(3) lcol(red) lpattern(solid) fcolor(red*.7) acolor(538rs9%50) alsty(nono) lwidth(thick) legend(off) caption("EB trendfile") xtitle("") ytitle("Support for SDPs") ylabel(, nogrid) caption(Source: EB trendfile)
graph save "EB 2a_simple", replace 

/* Part 3: EB part of Fig. 2c (Composition of SDPs) */
* Numerator: Number of manual workers M/F supporting SDPs
   *  nmwmsd, nmwfsd (created in Part 2)
* Denominator: Number of M/F who voted sd
gen sdm=1 if (prtyfam_sd==1 & gndr==1)
by  year cntry, sort: egen nsdm=total(sdm) if sdm==1
gen sdf=1 if (prtyfam_sd==1 & gndr==0)
by  year cntry, sort: egen nsdf=total(sdf) if sdf==1

*Proportions
gen     mwmsd_sdm = nmwmsd/nsdm
gen     mwfsd_sdf = nmwfsd/nsdf


* generate % male manual workers per country*/
by year cntry, sort: egen mwmcntry=max(mwmsd_sdm)
egen cntryuniquemw=tag(mwmcntry)
bys year cntry:egen cntryunique5=sum(mwmcntry) if cntryuniquemw==1
* generate % female manual workers per country*/
by year cntry, sort: egen mwfcntry=max(mwfsd_sdf)
egen cntryuniquemwf1=tag(mwfcntry)
bys year cntry:egen cntryunique6=sum(mwfcntry) if cntryuniquemwf1==1


/*APPENDIX: Figure D3c*/
twoway lpolyci cntryunique5 year if (cntryrr==1& nt1!="IT"), degree(3) ytitle("Proportion of SDPs vote") caption(Source: EB trendfile)lcolor(red) lwidth(thick) alsty(nono) fcolor(red*.7) acolor(red9%50) level(95)  ///
|| scatter mwmsd_sdm year if (cntryrr==1& nt1!="IT"), jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) graphregion(color(white)) ///
                                         mlabcolor(red) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique6 year if (cntryrr==1& nt1!="IT"), degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)   ///
|| scatter mwfsd_sdf year if (cntryrr==1& nt1!="IT"), jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(black) xtitle("") legend(off) 
graph save "EB 2c", replace

*MAIN TEXT: Figure 2c*/
twoway lpolyci cntryunique5 year if (cntryrr==1& nt1!="IT"), degree(3) ytitle("Proportion of SDPs vote") caption(Source: EB trendfile)lcolor(red) lwidth(thick) fcolor(red*.7) acolor(red9%50) level(95) graphregion(color(white)) alsty(nono) fxsize(100)|| 		lpolyci cntryunique6 year if (cntryrr==1& nt1!="IT"), degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)legend(off) ylabel(, nogrid) xtitle("")  
graph save "EB 2c_simple", replace


/* Part 4: EB part for Fig. 2b (Rate of support for the RR) */
* Numerator: Number of manual workers M/F + general sample voting RR
gen mwmrr=1 if (mnlwrk==1 & gndr==1 & prtyfam_rr==1)
gen mwfrr=1 if (mnlwrk==1 & gndr==0 & prtyfam_rr==1)
by  year cntry, sort: egen nmwmrr=total(mwmrr)   if mwmrr==1
by  year cntry, sort: egen nmwfrr=total(mwfrr)   if mwfrr==1
by  year cntry, sort: egen nrrv  =total(prtyfam_rr)  if prtyfam_rr==1

* Denominator: Number of manual workers M/F who voted and number of voters 
*  Created in Part 2: nmwmv, nmwfv, nv 

*Proportions
gen mwmrr_mwmv 	 =nmwmrr/nmwmv
gen mwfrr_mwfv   =nmwfrr/nmwfv
gen rrv_v        =nrrv/nv

* generate % male manual workers per country voting RR*/
by year cntry, sort: egen mwmcntryR=max(mwmrr_mwmv)
egen cntryuniquemwmR=tag(mwmcntryR)
bys year cntry:egen cntryunique9=sum(mwmcntryR) if cntryuniquemwmR==1
* generate % female manual workers per country*/
by year cntry, sort: egen mwfcntryR=max(mwfrr_mwfv)
egen cntryuniquemwfR=tag(mwfcntryR)
bys year cntry:egen cntryunique10=sum(mwfcntryR) if cntryuniquemwfR==1
* generate % rr voters per country*/
by year cntry, sort: egen rrv=max(rrv_v)
egen cntryuniquerv=tag(rrv)
bys year cntry:egen cntryunique11=sum(rrv) if cntryuniquerv==1

/*APPENDIX: Figure D3b*/
twoway lpolyci cntryunique11 year if cntryrr==1, degree(3) ytitle("Support for the FRPs") caption(Source: EB trendfile) lcolor(gs8) lwidth(thick) alsty(nono) fcolor(gs10*.7) acolor(538rs9%50) level(95)  ///
|| scatter rrv_v year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) graphregion(color(white)) ///
                                         mlabcolor(gs8) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique10 year if cntryrr==1, degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)   ///
|| scatter mwfrr_mwfv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(black) xtitle("") ///
|| lpolyci cntryunique9 year if cntryrr==1,  degree(3) lcol(red) fcolor(red*.7) acolor(538rs9%50) alsty(nono) ///
level(95) lwidth(thick) lpattern(solid) legend(off) ///
|| scatter mwmrr_mwmv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(red) xtitle("") 
graph save "EB 2b", replace

/*MAIN TEXT: Figure 2b*/
twoway lpolyci cntryunique11 year if cntryrr==1, degree(3) ytitle("Support for the FRPs") caption(Source: EB trendfile) lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) alsty(nono) level(95) fxsize(100) || ///										 
lpolyci cntryunique10 year if cntryrr==1, degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) level(95) lwidth(thick) lpattern(solid)  graphregion(color(white))  || lpolyci cntryunique9 year if cntryrr==1,  degree(3) lcol(red)   fcolor(red*.7) acolor(538rs9%50) ///
level(95) lwidth(thick) ylabel(,nogrid) lpattern(solid) alsty(nono) legend(off) xtitle("")
graph save "EB 2b_simple", replace


/* Part 5: EB panel for Fig. 2d (Composition of rr voters) */
* Numerator: Number of manual workers M/F supporting the rr 
  * mwmrr, mwfrr (created in Part 4)
  * Denominator: Number of manual workers M/F who voted and number of voters
gen rrm=1 if (prtyfam_rr==1 & gndr==1)
by  year cntry, sort: egen nrrm=total(rrm) if rrm==1
gen rrf=1 if (prtyfam_rr==1 & gndr==0)
by  year cntry, sort: egen nrrf=total(rrf) if rrf==1

*Proportions
gen     mwmrr_rrm = nmwmrr/nrrm
gen     mwfrr_rrf = nmwfrr/nrrf

* generate % male manual workers voting RR per country*/
by year cntry, sort: egen mwmrcntry=max(mwmrr_rrm)
egen cntryuniquemwmr=tag(mwmrcntry)
bys year cntry:egen cntryunique12=sum(mwmrcntry) if cntryuniquemwmr==1
* generate % female manual workers voting RR per country*/
by year cntry, sort: egen mwfrcntry=max(mwfrr_rrf)
egen cntryuniquemwfr=tag(mwfrcntry)
bys year cntry:egen cntryunique13=sum(mwfrcntry) if cntryuniquemwfr==1
/*APPENDIX: Figure F2d*/
twoway lpolyci cntryunique12 year if cntryrr==1, degree(3) ytitle("Proportion of FRPs vote") caption(Source: EB trendfile)lcolor(red) lwidth(thick) fcolor(red*.7) acolor(red9%50) alsty(nono) level(95) graphregion(color(white))  ///
|| scatter mwmrr_rrm year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(red) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique13 year if cntryrr==1, degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)   ///
|| scatter mwfrr_rrf year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ylabel(,nogrid) ///
                                         mlabcolor(black) xtitle("") legend(off) 
graph save "EB 2d", replace

/*MAIN TEXT: Figure 2d*/
twoway lpolyci cntryunique12 year if cntryrr==1, degree(3) ytitle("Proportion of FRPs vote") caption(Source: EB trendfile)lcolor(red) lwidth(thick) fcolor(red*.7) acolor(red9%50) alsty(nono) level(95)  || 		lpolyci cntryunique13 year if cntryrr==1, degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid) alsty(nono) fxsize(100) ylabel(,nogrid) legend(off) xtitle("") graphregion(color(white)) 
graph save "EB 2d_simple", replace
 

/* Part 6: EB part for Rate of support for the Conservative party family */
* Numerator: Number of manual workers M/F supporting conservative parties+ general sample voting cons
gen mwmcon=1 if (mnlwrk==1 & gndr==1 & prtyfam_con==1)
gen mwfcon=1 if (mnlwrk==1 & gndr==0 & prtyfam_con==1)
by  year cntry, sort: egen nmwmcon=total(mwmcon)   if mwmcon==1
by  year cntry, sort: egen nmwfcon=total(mwfcon)   if mwfcon==1
by  year cntry, sort: egen nconv  =total(prtyfam_con)if prtyfam_con==1

* Denominator: Number of manual workers M/F who voted and number of voters 
*  Created in Part 2: nmwmv, nmwfv, nv 

*Proportions
gen mwmcon_mwmv   =nmwmcon/nmwmv
gen mwfcon_mwfv   =nmwfcon/nmwfv
gen conv_v        =nconv/nv

* generate % male manual workers per country voting conservative*/
by year cntry, sort: egen mwmcntryC=max(mwmcon_mwmv)
egen cntryuniquemwmC=tag(mwmcntryC)
bys year cntry:egen cntryunique14=sum(mwmcntryC) if cntryuniquemwmC==1
* generate % female manual workers per country*/
by year cntry, sort: egen mwfcntryC=max(nmwfcon/nmwfv)
egen cntryuniquemwfC=tag(mwfcntryC)
bys year cntry:egen cntryunique15=sum(mwfcntryC) if cntryuniquemwfC==1
* generate % rr voters per country*/
by year cntry, sort: egen cv=max(conv_v)
egen cntryuniquecv=tag(cv)
bys year cntry:egen cntryunique16=sum(cv) if cntryuniquecv==1
/*APPENDIX: Figure D4*/
twoway lpolyci cntryunique16 year if cntryrr==1, degree(3) ytitle("Support for the Cons.") caption(Source: EB trendfile) lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) graphregion(color(white)) alsty(nono) level(95)  ///
|| scatter conv_v  year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(gs8) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique15 year if cntryrr==1, degree(3)lcol(black) fcolor(black*.50) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)  ///
|| scatter mwfcon_mwfv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(black) xtitle("") ///
|| lpolyci cntryunique14 year if cntryrr==1,  degree(3) lcol(red)   fcolor(red*.5) alsty(nono) acolor(538rs9%50) ///
level(95) lwidth(thick) lpattern(solid) legend(off) ///
|| scatter mwmcon_mwmv year if cntryrr==1, jitter(3) msymbol(i) ylabel(,nogrid) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(red) xtitle("") 

graph save "EB conservative", replace

/*MAIN TEXT: Figure3*/
twoway lpolyci cntryunique16 year if cntryrr==1,  degree(3) lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) alsty(nono) level(95) fxsize(100) ytitle("Support for the Cons.")   ||			lpolyci cntryunique15 year if cntryrr==1 , degree(3)lcol(black) fcolor(black*.5) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)|| lpolyci cntryunique14 year if cntryrr==1,  degree(3) lcol(red) lpa(solid) lwidth(thick)  fcolor(red*.5) acolor(538rs9%50) alsty(nono) legend(off) xtitle("") caption(Source: EB trendfile) ylabel(,nogrid) graphregion(color(white)) 
graph save "EB conservative_simple", replace

/* Part 7: EB part for Rate of support for the CD party family */
* Numerator: Number of manual workers M/F + general sample voting CD
gen mwmcd=1 if (mnlwrk==1 & gndr==1 & prtyfam_cd==1)
gen mwfcd=1 if (mnlwrk==1 & gndr==0 & prtyfam_cd==1)
by  year nation1, sort: egen nmwmcd=total(mwmcd)   if mwmcd==1
by  year nation1, sort: egen nmwfcd=total(mwfcd)   if mwfcd==1
by  year nation1, sort: egen ncdv  =total(prtyfam_cd) if prtyfam_cd==1

* Denominator: Number of manual workers M/F who voted and number of voters 
*  Created in Part 2: nmwmv, nmwfv, nv 

*Proportions
gen mwmcd_mwmv   =nmwmcd/nmwmv
gen mwfcd_mwfv   =nmwfcd/nmwfv
gen cdv_v        =ncdv/nv

* generate % male manual workers per country voting conservative*/
by year cntry, sort: egen mwmcntryCD=max(nmwmcd/nmwmv)
egen cntryuniquemwmCD=tag(mwmcntryCD)
bys year cntry:egen cntryunique17=sum(mwmcntryCD) if cntryuniquemwmCD==1
* generate % female manual workers per country*/
by year cntry, sort: egen mwfcntryCD=max(nmwfcd/nmwfv)
egen cntryuniquemwfCD=tag(mwfcntryCD)
bys year cntry:egen cntryunique18=sum(mwfcntryCD) if cntryuniquemwfCD==1
* generate % rr voters per country*/
by year cntry, sort: egen cdv=max(cdv_v)
egen cntryuniquecdv=tag(cdv)
bys year cntry:egen cntryunique19=sum(cdv) if cntryuniquecdv==1
/*APPENDIX: Figure D4*/
twoway lpolyci cntryunique19 year if cntryrr==1, degree(3) ytitle("Support for the Christian Democrats") caption(Source: EB trendfile)lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) alsty(nono) level(95)  ///
|| scatter cdv_v  year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(gs8) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique18 year if cntryrr==1, degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)   ///
|| scatter mwfcd_mwfv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(black) xtitle("") ///
|| lpolyci cntryunique17 year if cntryrr==1,  degree(3) lcol(red)   fcolor(red*.7) acolor(538rs9%50) alsty(nono) ///
level(95) lwidth(thick) lpattern(solid) legend(off) ///
|| scatter mwmcd_mwmv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) graphregion(color(white))  ylabel(,nogrid) ///
                                         mlabcolor(red) xtitle("") 

graph save "EB CD", replace

/*MAIN TEXT: Figure 3*/
twoway lpolyci cntryunique19 year if cntryrr==1,  degree(3) lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) alsty(nono) level(95) fxsize(100) ytitle("Support the Christian Democrats") caption(Source: EB trendfile)   ||			lpolyci cntryunique18 year if cntryrr==1 , degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)|| lpolyci cntryunique17 year if cntryrr==1,  degree(3) lcol(red)  lwidth(thick) lpattern(solid)  fcolor(red*.7) acolor(538rs9%50) legend(off) xtitle("")graphregion(color(white))  ylabel(,nogrid)
graph save "EB CD_simple", replace 

/* Part 8: EB part for Rate of support for the RL party family */
* Numerator: Number of manual workers M/F + general sample voting RL
gen mwmrl=1 if (mnlwrk==1 & gndr==1 & prtyfam_radicalleft==1)
gen mwfrl=1 if (mnlwrk==1 & gndr==0 & prtyfam_radicalleft==1)
by  year nation1, sort: egen nmwmrl=total(mwmrl)   if mwmrl==1
by  year nation1, sort: egen nmwfrl=total(mwfrl)   if mwfrl==1
by  year nation1, sort: egen nrlv  =total(prtyfam_radicalleft) if prtyfam_radicalleft==1

* Denominator: Number of manual workers M/F who voted and number of voters 
*  Created in Part 2: nmwmv, nmwfv, nv 

*Proportions
gen mwmrl_mwmv   =nmwmrl/nmwmv
gen mwfrl_mwfv   =nmwfrl/nmwfv
gen rlv_v        =nrlv/nv

* generate % male manual workers per country voting rl*/
by year cntry, sort: egen mwmcntryRL=max(nmwmrl/nmwmv)
egen cntryuniquemwmRL=tag(mwmcntryRL)
bys year cntry:egen cntryunique20=sum(mwmcntryRL) if cntryuniquemwmRL==1
* generate % female manual workers per country*/
by year cntry, sort: egen mwfcntryRL=max(nmwfrl/nmwfv)
egen cntryuniquemwfRL=tag(mwfcntryRL)
bys year cntry:egen cntryunique21=sum(mwfcntryRL) if cntryuniquemwfRL==1
* generate % rr voters per country*/
by year cntry, sort: egen rlv=max(rlv_v)
egen cntryuniquerlv=tag(rlv)
bys year cntry:egen cntryunique22=sum(rlv) if cntryuniquerlv==1
/*APPENDIX: Figure D4*/
twoway lpolyci cntryunique22 year if cntryrr==1, degree(3) ytitle("Support for the Radical Left") caption(Source: EB trendfile)lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) alsty(nono)  level(95)  ///
|| scatter rlv_v  year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) graphregion(color(white))  ylabel(,nogrid) ///
                                         mlabcolor(gs8) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique21 year if cntryrr==1, degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) level(95) lwidth(thick) lpattern(solid) alsty(nono)   ///
|| scatter mwfrl_mwfv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(black) xtitle("") ///
|| lpolyci cntryunique20 year if cntryrr==1,  degree(3) lcol(red)  lwidth(thick) lpattern(solid)  fcolor(red*.7) acolor(538rs9%50)alsty(nono)  ///
level(95) lwidth(thick) lpattern(solid) legend(off) ///
|| scatter mwmrl_mwmv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(red) xtitle("") 

graph save "EB RL", replace
/*MAIN TEXT: Figure 3*/
twoway lpolyci cntryunique22 year if cntryrr==1,  degree(3) lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) alsty(nono) level(95) fxsize(100) ytitle("Support the Radical Left") graphregion(color(white))  ylabel(,nogrid) caption(Source: EB trendfile)   ||			lpolyci cntryunique21 year if cntryrr==1 , degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono)  level(95) lwidth(thick) lpattern(solid) || lpolyci cntryunique20 year if cntryrr==1,  degree(3) lcol(red)  alsty(nono)  fcolor(red*.7) acolor(538rs9%50) lwidth(thick) lpattern(solid) legend(off) xtitle("")
graph save "EB RL_simple", replace

/* Part 9: EB part for Rate of support for the LIB party family */
* Numerator: Number of manual workers M/F + general sample voting lib
gen mwmlib=1 if (mnlwrk==1 & gndr==1 & prtyfam_lib==1)
gen mwflib=1 if (mnlwrk==1 & gndr==0 & prtyfam_lib==1)
by  year nation1, sort: egen nmwmlib=total(mwmlib)   if mwmlib==1
by  year nation1, sort: egen nmwflib=total(mwflib)   if mwflib==1
by  year nation1, sort: egen nrlib  =total(prtyfam_lib) if prtyfam_lib==1

* Denominator: Number of manual workers M/F who voted and number of voters 
*  Created in Part 2: nmwmv, nmwfv, nv 

*Proportions
gen mwmlib_mwmv   =nmwmlib/nmwmv
gen mwflib_mwfv   =nmwflib/nmwfv
gen libv_v        =nrlib/nv

* generate % male manual workers per country voting lib*/
by year cntry, sort: egen mwmcntrylib=max(nmwmlib/nmwmv)
egen cntryuniquemwmlib=tag(mwmcntrylib)
bys year cntry:egen cntryunique23=sum(mwmcntrylib) if cntryuniquemwmlib==1
* generate % female manual workers per country*/
by year cntry, sort: egen mwfcntrylib=max(nmwflib/nmwfv)
egen cntryuniquemwflib=tag(mwfcntrylib)
bys year cntry:egen cntryunique24=sum(mwfcntrylib) if cntryuniquemwflib==1
* generate % lib voters per country*/
by year cntry, sort: egen libv=max(libv_v)
egen cntryuniquelibv=tag(libv)
bys year cntry:egen cntryunique25=sum(libv) if cntryuniquelibv==1
/*APPENDIX: Figure D4*/
twoway lpolyci cntryunique25 year if cntryrr==1, degree(3) ytitle("Support for the Liberals") caption(Source: EB trendfile)lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) alsty(nono)  graphregion(color(white))  ylabel(,nogrid) level(95)  ///
|| scatter libv_v  year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(gs8) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique24 year if cntryrr==1, degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)   ///
|| scatter mwflib_mwfv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(black) xtitle("") ///
|| lpolyci cntryunique23 year if cntryrr==1,  degree(3) lcol(red)  lwidth(thick) lpattern(solid) fcolor(red*.7) acolor(538rs9%50) alsty(nono)  ///
level(95) lwidth(thick) lpattern(solid) legend(off) ///
|| scatter mwmlib_mwmv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(red) xtitle("") 

graph save "EB LIB", replace

/*MAIN TEXT: Figure3*/
twoway lpolyci cntryunique25 year if cntryrr==1,  degree(3) lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) alsty(nono) level(95) fxsize(100) ytitle("Support for the Liberals") graphregion(color(white))  ylabel(,nogrid) caption(Source: EB trendfile)   ||			lpolyci cntryunique24 year if cntryrr==1 , degree(3)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)|| lpolyci cntryunique23 year if cntryrr==1,  degree(3) lcol(red)  lwidth(thick) lpattern(solid) alsty(nono)   fcolor(red*.7) acolor(538rs9%50) legend(off)xtitle("")
graph save "EB LIB_simple" 

/* Part 10: EB part for Rate of support for the grn party family */
* Numerator: Number of manual workers M/F + general sample voting grn
gen mwmgrn=1 if (mnlwrk==1 & gndr==1 & prtyfam_grn==1)
gen mwfgrn=1 if (mnlwrk==1 & gndr==0 & prtyfam_grn==1)
by  year nation1, sort: egen nmwmgrn=total(mwmgrn)   if mwmgrn==1
by  year nation1, sort: egen nmwfgrn=total(mwfgrn)   if mwfgrn==1
by  year nation1, sort: egen nrgrn  =total(prtyfam_grn) if prtyfam_grn==1

* Denominator: Number of manual workers M/F who voted and number of voters 
*  Created in Part 2: nmwmv, nmwfv, nv 

*Proportions
gen mwmgrn_mwmv   =nmwmgrn/nmwmv
gen mwfgrn_mwfv   =nmwfgrn/nmwfv
gen grnv_v        =nrgrn/nv

* generate % male manual workers per country voting grn*/
by year cntry, sort: egen mwmcntrygrn=max(nmwmgrn/nmwmv)
egen cntryuniquemwmgrn=tag(mwmcntrygrn)
bys year cntry:egen cntryunique26=sum(mwmcntrygrn) if cntryuniquemwmgrn==1
* generate % female manual workers per country*/
by year cntry, sort: egen mwfcntrygrn=max(nmwfgrn/nmwfv)
egen cntryuniquemwfgrn=tag(mwfcntrygrn)
bys year cntry:egen cntryunique27=sum(mwfcntrygrn) if cntryuniquemwfgrn==1
* generate % grn voters per country*/
by year cntry, sort: egen grnv=max(grnv_v)
egen cntryuniquegrnv=tag(grnv)
bys year cntry:egen cntryunique28=sum(grnv) if cntryuniquegrnv==1
/*APPENDIX: Figure D4*/
twoway lpolyci cntryunique28 year if cntryrr==1, degree(2) ytitle("Support for the Greens") caption(Source: EB trendfile)lcolor(gs8) lwidth(thick) fcolor(gs10*.7) acolor(538rs9%50) graphregion(color(white))  ylabel(,nogrid)alsty(nono) level(95) xscale(r(1985(10)2002))  ///
|| scatter grnv_v  year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(gs8) ylab(, nogrid) fxsize(100) || ///										 
lpolyci cntryunique27 year if cntryrr==1, degree(2)lcol(black) fcolor(black*.7) acolor(538rs9%50) level(95) lwidth(thick) lpattern(solid) alsty(nono)  ///
|| scatter mwfgrn_mwfv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small) ///
                                         mlabcolor(black) xtitle("") ///
|| lpolyci cntryunique26 year if cntryrr==1,  degree(2) lcol(red)    lwidth(thick) lpattern(solid) fcolor(red*.7) acolor(538rs9%50) ///
level(95) lwidth(thick) alsty(nono) lpattern(solid) legend(off) ///
|| scatter mwmgrn_mwmv year if cntryrr==1, jitter(3) msymbol(i) mlabel(nt1) mlabsize(small)  ///
                                         mlabcolor(red) xtitle("") 

graph save "EB grn", replace
/*MAIN TEXT: Figure3*/
twoway lpolyci cntryunique28 year if cntryrr==1,  degree(2) lcolor(gs8) lwidth(thick) fcolor(gs8*.7) acolor(538rs9%50) alsty(nono) level(95) fxsize(100) ytitle("Support for the Greens")graphregion(color(white))  ylabel(,nogrid) caption(Source: EB trendfile)   ||			lpolyci cntryunique27 year if cntryrr==1 , degree(2)lcol(black) fcolor(black*.7) acolor(538rs9%50) alsty(nono) level(95) lwidth(thick) lpattern(solid)|| lpolyci cntryunique26 year if cntryrr==1,  degree(2) lcol(red)  lwidth(thick) lpattern(solid)  fcolor(red*.7) acolor(538rs9%50) alsty(nono) legend(off)xtitle("")
graph save "EB grn_simple", replace 



log close

